﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using EmbeddedSharp.Scripting;

namespace Zove.Desktop {
    public partial class LocalView : DockContent {

        public IContext Context {
            get;
            set;
        }

        public LocalView() {
            InitializeComponent();

            this.Load += new EventHandler(LocalView_Load);
        }

        public LocalView(IContext context)
            : this() {
            this.Context = context;
        }

        public void LocalView_Load(object sender, EventArgs e) {
            StackFrame topFrame = Context.Peep();
            this.gvLocal.CellValueChanged += new DataGridViewCellEventHandler(gvLocal_CellValueChanged);

            foreach (string key in topFrame.Keys) {
                string value = topFrame[key].ToString();
                this.gvLocal.Rows.Add(new string[] { key, value });
            }
        }

        public void gvLocal_CellValueChanged(
            object sender, DataGridViewCellEventArgs e) {
            StackFrame topFrame = Context.Peep();

            string key = this.gvLocal.Rows[e.RowIndex].Cells[0].Value.ToString();
            object value = this.gvLocal.Rows[e.RowIndex].Cells[1].Value;

            topFrame[key] = value;
        }
    }
}
